package com.ptswitch.material.pages.material;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.ptswitch.material.model.material.Material;
import com.ptswitch.material.pages.base.PageBase;
import com.ptswitch.material.service.MaterialService;
import com.ptswitch.material.util.security.PermissionUtil;

public class ViewMaterial2 extends PageBase {
    @Inject
    private MaterialService materialSer;
    @Property
    private Material material;
    private long id;

    Object withInit(long id) {
        init(id);
        return this;
    }

    @OnEvent(value = EventConstants.ACTIVATE)
    Object init(long id) {
        checkPermitted(PermissionUtil.MaterialView);
        this.id = id;
        return null;
    }

    @SetupRender
    void display() {
        material = materialSer.findById(id, MaterialService.Init_ContractItems);
    }

    @OnEvent(value = EventConstants.PASSIVATE)
    Object onPassivate() {
        return id;
    }
}
